package com.itheima.a01mymap;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class A03_MapDemo3 {
    public static void main(String[] args) {
        //创建集合
        Map<String, String> map = new HashMap<>();

        //添加对象
        map.put("郭靖", "黄蓉");
        map.put("孙悟空", "白骨精");

        //进行遍历
        Set<Map.Entry<String, String>> entries = map.entrySet();
        for (Map.Entry<String, String> entry : entries) {
            String key = entry.getKey();
            String value = entry.getValue();
            System.out.println(key + "--" + value);
        }
        //输出结果


        //使用迭代器进行遍历集合
        Iterator<Map.Entry<String, String>> it = entries.iterator();
        while(it.hasNext()){
            Map.Entry<String, String> entry = it.next();
            String key = entry.getKey();
            String value = entry.getValue();
            System.out.println(key + "--" + value);
        }
    }
}
